import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QVBoxLayout, QPushButton


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建文本输入框
        self.lineEdit = QLineEdit()

        # 创建按钮
        self.button = QPushButton('获取文本')
        self.button.clicked.connect(self.show_text)

        layout = QVBoxLayout()
        layout.addWidget(self.lineEdit)
        layout.addWidget(self.button)
        self.setLayout(layout)

        self.setWindowTitle('文本输入框示例')
        self.setGeometry(300, 300, 300, 200)
        self.show()

    def show_text(self):
        input_text = self.lineEdit.text()
        print(input_text)
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())